package com.zh.mp.demo.listener;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

@Slf4j
public class MyHttpRequestListener implements ServletRequestListener {

    private static int onLineCount = 0;

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        HttpServletRequest request = (HttpServletRequest) sre.getServletRequest();
        log.info("requestListener:  create--> " + request.getSession().getId());
        onLineCount ++;
    }

    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        HttpServletRequest request = (HttpServletRequest) sre.getServletRequest();
        log.info("requestListener: destroy--> " + request.getSession().getId());
        onLineCount--;
    }
}

